﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp.Exam2
{
    class Person
    {
        private string _firstName;
        private string _lastName;
        private string _emailAddress;
        private DateTime _dayOfBirth;

        public string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        public string LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }

        public string EmailAddress
        {
            get { return _emailAddress; }
            set { _emailAddress = value; }
        }

        public DateTime DayOfBirth
        {
            get { return _dayOfBirth; }
            set { _dayOfBirth = value; }
        }

        public bool IsBirthday()
        {
            return (DateTime.Today.Day == _dayOfBirth.Day && DateTime.Today.Month == _dayOfBirth.Month);
        }

        public bool Adult
        {
            get
            {
                DateTime today = DateTime.Today;
                if (today.Year - _dayOfBirth.Year > 18)
                    return true;
                else if (today.Year - _dayOfBirth.Year == 18)
                {
                    if (today.Month > _dayOfBirth.Month)
                        return true;
                    else if (today.Month == _dayOfBirth.Month)
                    {
                        if (today.Day >= _dayOfBirth.Day)
                            return true;
                    }
                }

                bool result = (today.Year - _dayOfBirth.Year - 18) * 366 +
                              (today.Month - _dayOfBirth.Month) * 31 + (today.Day - _dayOfBirth.Day) >= 0;
                return false;
            }
        }

        public string SunSign
        {
            get
            {
                int[,] sign = {
                              {21,3,20,4},{21,4,20,5},{21,5,21,6},
                              {22,6,22,7},{23,7,22,8},{23,8,22,9},
                              {23,9,23,10},{24,10,21,11},{22,11,21,12},
                              {22,12,19,1},{20,1,18,2},{19,2,20,3}
                };
                string[] nameSign =
                    {
                        "Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricornus", "Aquarius", "Pisces"
                    };
                int day = _dayOfBirth.Day, month = _dayOfBirth.Month;

                for (int i = 0; i < 12; i++)
                    if ((month == sign[i, 1] && day >= sign[i, 0])
                        || (month == sign[i, 3] && day <= sign[i, 2]))
                        return nameSign[i];

                return "Other";
            }
        }

        public Person()
        {
            this._firstName = "";
            this._lastName = "";
            this._emailAddress = "";
            this._dayOfBirth = DateTime.Now;
        }

        public Person(string firstName, string lastname, string email)
        {
            this._firstName = firstName;
            this._lastName = lastname;
            this._emailAddress = email;
        }

        public Person(string firstName, string lastname, DateTime day)
        {
            this._firstName = firstName;
            this._lastName = lastname;
            this._dayOfBirth = day;
        }

        public Person(string firstName, string lastName, string email, DateTime day)
        {
            this._firstName = firstName;
            this._lastName = lastName;
            this._emailAddress = email;
            this._dayOfBirth = day;
        }

        public static void Test()
        {
            Person p = new Person("Firstname", "Lastname", "email@email.com", new DateTime(1995, 8, 7));

            Console.WriteLine("Your Firstname : {0}", p.FirstName);
            Console.WriteLine("Your Lastname : {0}", p.LastName);
            Console.WriteLine("Your Email : {0}", p.EmailAddress);
            Console.WriteLine("Your Birthday : {0}", p.DayOfBirth.ToShortDateString());

            Console.WriteLine("You're adult : {0}", p.Adult);
            Console.WriteLine("Today is your birthday : {0}", p.IsBirthday());
            Console.WriteLine("Your sunsign : {0}", p.SunSign);
        }
    }
}
